package com.bwie.assist.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.bwie.assist.entity.Root;
import com.bwie.common.utils.HttpUtils;
import com.bwie.common.utils.R;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName RobotController
 * @Description TODO
 * @Author 李奉武
 * @Motto 逆水行舟, 不进则退
 * @Date 2022/3/29 11:43
 * @Version 1.0
 */
@RestController
@RequestMapping("assist/robot")
public class RobotController {

    @Value("${tulin.userInfo.apiKey}")
    String key;

    @RequestMapping("/sendmsg")
    public R  sendmsg(@RequestBody Root root) throws Exception {
        System.out.println(key);
        root.getUserInfo().setApiKey(key);
        HttpResponse post = HttpUtils.doPost("http://openapi.turingapi.com", "/openapi/api/v2", "post", null,null, JSON.toJSONString(root));
        String s = EntityUtils.toString(post.getEntity());
        com.bwie.assist.pojo.Root root1 = JSON.parseObject(s, new TypeReference<com.bwie.assist.pojo.Root>() {
        });
        System.out.println("root1 = " + root1);
        return R.ok().put("robot", root1);
    }
}
